
const SERVER = require('../../utils/index');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: '1',
    list:[],
    actv:0,//收藏
    guan:0,//关注
    id:'',
    currentIndex: 0,
    swiperList: ['https://img2.baidu.com/it/u=3681880960,455182084&fm=26&fmt=auto&gp=0.jpg', 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.pconline.com.cn%2Fimages%2Fupload%2Fupc%2Ftx%2Fphotoblog%2F1104%2F11%2Fc2%2F7278725_7278725_1302501879093_mthumb.jpg&refer=http%3A%2F%2Fimg.pconline.com.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1621136242&t=b244e8ab6d2a051e5da25077c5b0d91b']
  },

  /* 跑马灯当前index */
  currentChange(e) {
    this.setData({
      currentIndex: e.detail
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  //点击客服
  makeCall: function () {
    var telephone = '010-65903765'//手机号
    var fixed_telephone = '010-65903178'//固话

    if (telephone && fixed_telephone && telephone != fixed_telephone){
        wx.showActionSheet({
          itemList: [telephone, fixed_telephone],
          success(res) {
            if (res.tapIndex === 0) {
              wx.makePhoneCall({ //点击确定按钮  调用小程序拨打电话的api  
                phoneNumber: telephone,//从后台获取到的电话号码
                success: function () {
                  console.log('拨打电话成功' + telephone)
                },
                fail: function () {
                  console.log("拨打电话失败")
                }
              })
            } else if (res.tapIndex === 1) {
              wx.makePhoneCall({ //点击确定按钮  调用小程序拨打电话的api  
                phoneNumber: fixed_telephone,//从后台获取到的电话号码
                success: function () {
                  console.log('拨打电话成功' + fixed_telephone )
                },
                fail: function () {
                  console.log("拨打电话失败")
                }
              })
            }
          },
          fail(res) {
            console.log("拨打电话失败")
          }
        })
  
    } else if (telephone === fixed_telephone){
      //弹出dialog弹出框
      wx.showModal({
        content: "确认拨打" + fixed_telephone + "吗",
        confirmColor: '#2EA7E0',
        success(res) {
          if (res.cancel) {
            // 用户点击了取消属性的按钮 
            return false
          } else if (res.confirm) {
            wx.makePhoneCall({ //调用小程序拨打电话的api
              phoneNumber: fixed_telephone, //获取到的电话号码
              success: function () {
                console.log('拨打电话成功')
              },
              fail: function () {
                console.log("拨打电话失败")
              }
            })
          }
        }
      })
    } else if (!telephone){
      //弹出dialog弹出框
      wx.showModal({
        content: "确认拨打" + fixed_telephone + "吗",
        confirmColor: '#2EA7E0',
        success(res) {
          if (res.cancel) {
            // 用户点击了取消属性的按钮 
            return false
          } else if (res.confirm) {
            wx.makePhoneCall({ //调用小程序拨打电话的api
              phoneNumber: fixed_telephone, //获取到的电话号码
              success: function () {
                console.log('拨打电话成功')
              },
              fail: function () {
                console.log("拨打电话失败")
              }
            })
          }
        }
      })
    } else if (!fixed_telephone){
      //弹出dialog弹出框
      wx.showModal({
        content: "确认拨打" + telephone + "吗",
        confirmColor: '#2EA7E0',
        success(res) {
          if (res.cancel) {
            // 用户点击了取消属性的按钮 
            return false
          } else if (res.confirm) {
            wx.makePhoneCall({ //调用小程序拨打电话的api
              phoneNumber: telephone, //获取到的电话号码
              success: function () {
                console.log('拨打电话成功')
              },
              fail: function () {
                console.log("拨打电话失败")
              }
            })
          }
        }
      })
    } else if (!fixed_telephone && !fixed_telephone){
      wx.showModal({
        content: "暂无联系电话",
        confirmColor: '#2EA7E0',
        showCancel: false,//不显示取消按钮
        success(res) {
          if (res.confirm) {
             return false
          }
        }
      })
    }
  },
  kefu(){
   
  },
  //点击添加关注
  follow(e){
if(this.data.guan==0){
  let pamers={
    followType:2,
    specLotId:e.currentTarget.dataset.id
  }
 var that=this
  wx.request({//首页数据
    url: '' + SERVER.SERVER_DIMAIN + '/customer/follow/addfollow', 
    data: JSON.stringify(pamers),
    header: {
      'content-type': 'application/json' ,
      "TENANT-ID":"2",
      "Connection":'Keep-alive',
      "Accept-Encoding":'gzip,deflate,br',
      "Authorization":"Bearer "+wx.getStorageSync('token'),
      "DEVICE_TYPE":'IOS'
    },
    method: 'post',
    success: function (res) {
      if(res.data.msg=='操作成功'){
        that.setData({
          guan:1
        })
        wx.showToast({

          title: '关注成功',
     
          icon: 'success',
     
          duration: 2000//持续的时间
     
        })
      }
    }
  });
}
else{
  let pamers={
    followType:2,
    specLotId:e.currentTarget.dataset.id
  }
 var that=this
  wx.request({//首页数据
    url: '' + SERVER.SERVER_DIMAIN + '/customer/follow/removefollow', 
    data: JSON.stringify(pamers),
    header: {
      'content-type': 'application/json' ,
      "TENANT-ID":"2",
      "Connection":'Keep-alive',
      "Accept-Encoding":'gzip,deflate,br',
      "Authorization":"Bearer "+wx.getStorageSync('token'),
      "DEVICE_TYPE":'IOS'
    },
    method: 'post',
    success: function (res) {
      if(res.data.msg=='操作成功'){
        that.setData({
          guan:0
        })
        wx.showToast({

          title: '取消成功',
     
          icon: 'success',
     
          duration: 2000//持续的时间
     
        })
      }
    }
  });
}
  },
  //点击收藏
  show(e){
    if(this.data.actv==0){
      let pamers={
        favType:2,
        specLotId:e.currentTarget.dataset.id
      }
     var that=this
      wx.request({//首页数据
        url: '' + SERVER.SERVER_DIMAIN + '/customer/favoritesspec/addfav', 
        data: JSON.stringify(pamers),
        header: {
          'content-type': 'application/json' ,
          "TENANT-ID":"2",
          "Connection":'Keep-alive',
          "Accept-Encoding":'gzip,deflate,br',
          "Authorization":"Bearer "+wx.getStorageSync('token'),
          "DEVICE_TYPE":'IOS'
        },
        method: 'post',
        success: function (res) {
          that.setData({
            actv:res.data.msg
          })
          wx.showToast({

            title: '收藏成功',
       
            icon: 'success',
       
            duration: 2000//持续的时间
       
          })
        }
      });
    }else{
      
      let pamers={
        favType:2,
        specLotId:e.currentTarget.dataset.id
      }
     var that=this
      wx.request({//首页数据
        url: '' + SERVER.SERVER_DIMAIN + '/customer/favoritesspec/removefav', 
        data: JSON.stringify(pamers),
        header: {
          'content-type': 'application/json' ,
          "TENANT-ID":"2",
          "Connection":'Keep-alive',
          "Accept-Encoding":'gzip,deflate,br',
          "Authorization":"Bearer "+wx.getStorageSync('token'),
          "DEVICE_TYPE":'IOS'
        },
        method: 'post',
        success: function (res) {
          console.log(res)
          wx.showToast({

            title: '取消成功',
       
            icon: 'success',
       
            duration: 2000//持续的时间
       
          })
          that.setData({
            actv:0
          })
        }
      });
    }
  
  },
  tiaozhuan(){
    wx.navigateTo({
      url: '/pages/bzjpage/bzjpage'
    })
  },
  gotowtpage(e){
    wx.navigateTo({
      url: '/pages/wlwtpage/wlwtpage?id='+e.currentTarget.dataset.id
    })
  },
  
  onLoad: function (options) {
    this.setData({
      id:options.id
    })
    
    var that=this
    
    wx.request({//首页数据
      url: '' + SERVER.SERVER_DIMAIN + '/customer/lot/lotDetail', 
      data: {
        lotId:that.data.id
      },
      header: {
        'content-type': 'application/json' 
      },
      method: 'get',
      success: function (res) {
        that.setData({
          list:res.data.data
        })
        
     
       
      }
    });
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})